package GUI;

import java.awt.Color;
import java.awt.Component;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Handler;

import javax.naming.CommunicationException;

import dados.Arquivo;

import Protocolo.MiniTCP;

import info.monitorenter.gui.chart.Chart2D;
import info.monitorenter.gui.chart.ITrace2D;
import info.monitorenter.gui.chart.traces.Trace2DLtd;


public class GraficoVelocidadeCliente {

	private Chart2D chart;
	private ITrace2D trace;
	private Timer timer;
	private TimerTask task;
	private double m_y;
	private long m_starttime;
	private Arquivo arquivo;

	public GraficoVelocidadeCliente(Arquivo arquivo, double m_y){
		this.m_y = 0;
		this.trace = new Trace2DLtd(200);
		this.chart = new Chart2D();
		this.timer = new Timer(true);
		this.arquivo = arquivo;
	}

	public Component montarGrafico(){
		chart.addTrace(trace);
		TimerTask task = new TimerTask(){

			private double m_y = 0;
			private double m_starttime  = System.currentTimeMillis();;

			@Override
			public void run() {
				m_y = arquivo.getBytesRecebidos();
				trace.setName("Velocidade de upload do arquivo.");
				trace.setColor(Color.red);
				trace.addPoint(((double) System.currentTimeMillis() - this.m_starttime), this.m_y);
			}

		};
		timer.schedule(task, 1000, 1000);
		return chart;


	}
}



